home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / winclock / clock.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-17  |  5.0 KB  |  160 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   0  'None
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   1605
  7.    ClientLeft      =   5250
  8.    ClientTop       =   3750
  9.    ClientWidth     =   1605
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1605
  12.    ScaleMode       =   0  'User
  13.    ScaleWidth      =   1605
  14.    ShowInTaskbar   =   0   'False
  15.    Begin VB.Timer Timer1 
  16.       Interval        =   1
  17.       Left            =   600
  18.       Top             =   480
  19.    End
  20. Attribute VB_Name = "Form1"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26. Dim second As Long, minute As Long, hour As Long
  27. Dim second_Prv As Long, minute_Prv As Long, hour_Prv As Long
  28. Dim Pos_x(1 To 60) As Double
  29. Dim Pos_y(1 To 60) As Double
  30. Dim Minute_to_x As Double, Minute_to_y As Double
  31. Dim Hour_to_x As Double, Hour_to_y As Double
  32. Dim swp As Long, shp As Long
  33. Dim fwp As Long, fhp As Long
  34. Dim i As Long, j As Long, pi As Double, c As Long
  35. Private Sub Form_DblClick()
  36. Me.Visible = False
  37. Unload Me
  38. End Sub
  39. Private Sub Form_Load()
  40. 'Storing Pi
  41. pi = 3.1415629
  42. 'Scr Width and height by pixels
  43. swp = Screen.Width / Screen.TwipsPerPixelX
  44. shp = Screen.Height / Screen.TwipsPerPixelY
  45. 'Form Width and height by pixels. Of course
  46. 'we are not setting them here, but storing
  47. fwp = 105
  48. fhp = 105
  49. 'Here, we are creating an elliptic region,
  50. c = CreateEllipticRgn(0, 0, 103, 102)
  51. 'As you see, the function returnes an id for the region,
  52. 'And we are seting the region as our form
  53. SetWindowRgn Form1.hWnd, c, True
  54. With Form1
  55.    .BackColor = vbBlack
  56.    .Picture = LoadPicture(VB.App.Path + "\clock.bmp")
  57.    .Move Screen.Width - (fwp + 10) * Screen.TwipsPerPixelX, _
  58.          10 * Screen.TwipsPerPixelY, _
  59.          fwp * Screen.TwipsPerPixelX, _
  60.          fhp * Screen.TwipsPerPixelY
  61. End With
  62. 'Storing these calculatings into an array matrix,
  63. 'And calling them from there,
  64. 'is faster around 20 times than calculating.
  65. 'This, is a mathamatical process, But I think you can
  66. 'understand what's going on here.
  67. For i = 1 To 60
  68. Pos_x(i) = 35 * Cos(-(pi / 2) + (i * (pi / 30)))
  69. Pos_y(i) = 35 * Sin(-(pi / 2) + (i * (pi / 30)))
  70. Next i
  71. 'Set scalemode to pixels.
  72. Form1.ScaleMode = vbPixels
  73. End Sub
  74. Private Sub Timer1_Timer()
  75. 'Take the time of computer
  76. second = Val(Right(Time$, 2))
  77. second_Prv = second - 1
  78. minute = Val(Mid(Time$, 4, 2))
  79. minute_Prv = minute - 1
  80. 'The clock is analogue. So:
  81. hour = Val(Left(Time$, 2)) Mod 12
  82. hour_Prv = hour - 1
  83. 'Reset:
  84. If hour = 0 Then hour = 12: hour_Prv = 11
  85. If minute = 0 Then minute = 60: minute_Prv = 59
  86. If second = 0 Then second = 60: second_Prv = 59
  87. If hour = 1 Then hour_Prv = 0
  88. If minute = 1 Then minute_Prv = 60
  89. If second = 1 Then second_Prv = 60
  90. 'We need to do the clearing together, and first.
  91. 'Or something we drawed might be cleared
  92. 'Clear
  93. Form1.Line (51, 50)-(51 + Pos_x(second_Prv), 50 + Pos_y(second_Prv)), vbWhite
  94. Minute_to_x = 51 + 0.9 * Pos_x(minute_Prv)
  95. Minute_to_y = 50 + 0.9 * Pos_y(minute_Prv)
  96. draw_minute False
  97. If second = 60 Then
  98.    'This means a first moment of a minute
  99.    'Clearing
  100.    If minute < 12 Or minute = 60 Then
  101.       Hour_to_x = 51 + 0.7 * Pos_x(hour_Prv * 5 + Int(59 / 12))
  102.       Hour_to_y = 50 + 0.7 * Pos_y(hour_Prv * 5 + Int(59 / 12))
  103.    Else
  104.       If minute = 12 Then
  105.          Hour_to_x = 51 + 0.7 * Pos_x(hour * 5 + Int(minute_Prv / 12))
  106.          Hour_to_y = 50 + 0.7 * Pos_y(hour * 5 + Int(minute_Prv / 12))
  107.       Else
  108.          If hour = 12 Then hour = 0
  109.          Hour_to_x = 51 + 0.7 * Pos_x(hour * 5 + Int(minute_Prv / 12))
  110.          Hour_to_y = 50 + 0.7 * Pos_y(hour * 5 + Int(minute_Prv / 12))
  111.          If hour = 0 Then hour = 12
  112.       End If
  113.    End If
  114.    draw_hour False
  115. End If
  116. 'Drawing:
  117. Draw_Second
  118. Minute_to_x = 51 + 0.9 * Pos_x(minute)
  119. Minute_to_y = 50 + 0.9 * Pos_y(minute)
  120. draw_minute True
  121. If hour = 12 Then hour = 0
  122. If minute = 60 Then minute = 0
  123. If hour = 0 And minute < 12 Then hour = 12
  124. If hour = 0 And minute = 0 Then hour = 12
  125. Hour_to_x = 51 + 0.7 * Pos_x(hour * 5 + Int(minute / 12))
  126. Hour_to_y = 50 + 0.7 * Pos_y(hour * 5 + Int(minute / 12))
  127. draw_hour True
  128. End Sub
  129. Sub Draw_Second()
  130. Form1.Line (51, 50)-(51 + Pos_x(second), 50 + Pos_y(second)), RGB(128, 128, 128)
  131. End Sub
  132. Sub draw_minute(Draw_Or_Clear As Boolean)
  133. 'I think, easy to understand
  134.    Dim Draw_Color As ColorConstants
  135.    If Draw_Or_Clear = True Then
  136.       Draw_Color = RGB(128, 128, 128)
  137.    Else
  138.       Draw_Color = vbWhite
  139.    End If
  140.    For i = 50 To 52
  141.       For j = 49 To 51
  142.          Form1.Line (i, j)-(Minute_to_x, Minute_to_y), Draw_Color
  143.       Next j
  144.    Next i
  145. End Sub
  146. Sub draw_hour(Draw_Or_Clear As Boolean)
  147. 'I think, easy to understand
  148.    Dim Draw_Color As ColorConstants
  149.    If Draw_Or_Clear = True Then
  150.       Draw_Color = RGB(128, 128, 128)
  151.    Else
  152.       Draw_Color = vbWhite
  153.    End If
  154.    For i = 49 To 53
  155.       For j = 48 To 52
  156.          Form1.Line (i, j)-(Hour_to_x, Hour_to_y), Draw_Color
  157.       Next j
  158.    Next i
  159. End Sub
  160.